<template>
  <div>
    <h1>当前求和为{{ $store.state.sum }}</h1>
    <select v-model.number="number">
      <!-- 或者:value -->
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="addNumber">+</button>
    <button @click="reduceNumber">-</button>
    <button @click="oddAddNumber">当前的求和值为奇数再加</button>
    <button @click="delayAddNumber">等500ms后再加</button>
  </div>
</template>

<script>
export default {
  name: "Count",
  data() {
    return {
      number: 1, //默认选中1
    };
  },
  methods: {
    addNumber() {
      // this.$store.dispatch("jia", this.number);先与actions连接再与mutations连接
      this.$store.commit("JIA", this.number); //直接与mutations连接
    },
    reduceNumber() {
      // this.$store.dispatch("jian", this.number);先与actions连接再与mutations连接
      this.$store.commit("JIAN", this.number); //直接与mutations连接
    },
    oddAddNumber() {
      this.$store.dispatch("oddjia", this.number);
    },
    delayAddNumber() {
      this.$store.dispatch("delayjia", this.number);
    },
  },
};
</script>

<style scoped>
button {
  margin: 0 5px 0 5px;
}
</style>